package com.yx.front.controller;


import com.yx.front.config.global.CommonResult;
import com.yx.front.manager.CommentsReplyManager;
import com.yx.front.model.param.CommentsInfoParam;
import com.yx.front.model.param.CommentsParam;
import com.yx.front.model.param.CommentsReplyParam;
import com.yx.front.model.vo.CommentsReplyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评论回复表 前端控制器
 * </p>
 *
 * @author YangXiong
 * @since 2023-04-03
 */
@Slf4j
@RestController
@Api(tags = "子评论信息控制器")
@RequestMapping("/comments-reply")
public class CommentsReplyController {
    @Resource
    private CommentsReplyManager commentsReplyManager;

    @PostMapping("/page")
    @ApiOperation("根据主题id获取评论列表")
    public CommonResult<List<CommentsReplyVo>> getPageByMainId(@RequestBody CommentsParam param){
        log.info("CommentsReplyController info getPageByMainId CommentsParam={}", param);
        return commentsReplyManager.getPageByMainId(param);
    }

    @PostMapping("/insert")
    @ApiOperation("插入一条评论")
    @PreAuthorize("@ex.hasAuthority('create')")
    public CommonResult<String> insert(@RequestBody CommentsReplyParam param){
        log.info("CommentsInfoController info insert CommentsReplyParam={}", param);
        Boolean result = commentsReplyManager.insert(param);
        if (result) {
            return CommonResult.success("评论成功");
        }
        return CommonResult.fail("评论失败");
    }

    @PostMapping("/delete")
    @ApiOperation("删除一条评论")
    @PreAuthorize("@ex.hasAuthority('delete')")
    public CommonResult<String> delete(@RequestBody CommentsReplyParam param){
        log.info("CommentsInfoController info delete CommentsReplyParam={}", param);
        Boolean result = commentsReplyManager.delete(param);
        if (result) {
            return CommonResult.success("删除成功");
        }
        return CommonResult.fail("删除失败");
    }
}

